package utils;

import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	public static int getDay(Date d){
		Calendar cal = Calendar.getInstance();
		cal.setTime(d);
		return cal.get(Calendar.DAY_OF_MONTH);
	}
	
	public static int getMonth(Date d){
		Calendar cal = Calendar.getInstance();
		cal.setTime(d);
		return cal.get(Calendar.MONTH);
	}
	
	public static int getYear(Date d){
		Calendar cal = Calendar.getInstance();
		cal.setTime(d);
		return cal.get(Calendar.YEAR);
	}
	
	public static int monthStr2Int(String m) throws ParseException {
		Date date = new SimpleDateFormat("MMMM").parse(m);
	    Calendar cal = Calendar.getInstance();
	    cal.setTime(date);
	    int month = cal.get(Calendar.MONTH);
	    return month;
	}
	
	public static String monthInt2String(int m){
		return new DateFormatSymbols().getMonths()[m];
	}
	
	public static int getDaysOfMonth(String m, int y) throws ParseException{
		return getDaysOfMonth(monthStr2Int(m), y);
	}
	
	public static int getDaysOfMonth(int m, int y) throws ParseException{
		Calendar cal = Calendar.getInstance();  
	    cal.set(y, m, 1);
		return cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	}

	public static void main(String args[]) throws ParseException {
		
		/*int n = 2;
		String s = "Enero";
		
		System.out.println(monthInt2String(n));
		System.out.println(monthStr2Int(s));*/
		
		System.out.println(getDaysOfMonth("Febrero",2013));
	}

}